import java.util.Scanner;
public class Main{
    //进制转换
    public static void convertSystem(int m,int n){
        if(m==0){
            System.out.print(0);
        }
        String[] num=new String[]{"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};    //对应的数字规则参考16进制
        StringBuffer ret=new StringBuffer();
        boolean bool=false;    //判断是否为负数
        if(m<0){
            m=-m;
            bool=true;
        }
        int quotient=m;    //商
        int remainder=0;    //余数
        while(quotient!=0){    // 短除法
            remainder=quotient%n;
            quotient=quotient/n;
            ret.append(num[remainder]);
        }
        if(bool){    //为负数时，在前面加上负号
            ret.append("-");
        }
        System.out.print(ret.reverse().toString());
    }
    
    public static void main(String[] args){
        Scanner scanner=new Scanner(System.in);
        int m=scanner.nextInt();
        int n=scanner.nextInt();
        convertSystem(m,n);
    }
    
}